package com.work.straighttalk.ui.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.work.straighttalk.R;
import com.work.straighttalk.app.BaseFragment;
import com.work.straighttalk.presenter.CleanHistoryPresenterImpl;
import com.work.straighttalk.presenter.i.CleanHistoryPresenterI;
import com.work.straighttalk.ui.NewFriendsActivity;
import com.work.straighttalk.ui.i.CallMenuVI;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.pedant.SweetAlert.SweetAlertDialog;

/**
 * Created by dllo on 16/3/1.
 */
public class CallFragment extends BaseFragment implements CallMenuVI {
    @Bind(R.id.btn)
    Button btn;
    private CleanHistoryPresenterI cleanHistoryPresenterI;
    private SweetAlertDialog sd;
    private Context context;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context = context;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_call, container, false);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        cleanHistoryPresenterI = new CleanHistoryPresenterImpl(this);
    }

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        inflater.inflate(R.menu.main_toolbar_call, menu);
        super.onCreateOptionsMenu(menu, inflater);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void cleanHistory() {
        cleanHistoryPresenterI.cleanCallHistory();
    }

    @Override
    public void toAnotherActivity(int id) {

    }

    @Override
    public void showLoadingDialog() {
        sd = new SweetAlertDialog(context, SweetAlertDialog.PROGRESS_TYPE);
        sd.setTitleText("删除中");
        sd.setCancelable(false);
    }

    @Override
    public void showSuccessDialog() {
        if (null == sd) {
            sd = new SweetAlertDialog(context);
        }
        sd.setTitleText("删除成功")
                .setConfirmText("OK").changeAlertType(SweetAlertDialog.SUCCESS_TYPE);
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick(R.id.btn)
    public void startbtn() {
        Intent intent = new Intent(getActivity(), NewFriendsActivity.class);
        startActivity(intent);
    }
}
